<template>
  <div class="activityIndex" style="padding-bottom:50px">
    <div class="regCon" @click="regClick"></div>
    <div class="indexImgContainer">
      <div class="headCon">
        <!-- <img class="bgImg" src="../../../assets/切图/直播页面-正式稿_01.jpg" alt /> -->
        <van-swipe :autoplay="5000">
          <van-swipe-item v-for="(item, index) in swipeImg" :key="index">
            <img :src="item.img" class="swipeImg" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="countCon">
        <div class="countContainer">
          <div class="count">
            <div class="countTop">{{peopleCount.involvedCount}}</div>
            <div>已报名人数</div>
          </div>
          <div class="count">
            <div class="countTop">{{peopleCount.assistCount}}</div>
            <div>已分享次数</div>
          </div>
          <div class="count">
            <div class="countTop">{{peopleCount.browseCount}}</div>
            <div>已浏览人数</div>
          </div>
        </div>
      </div>
      <div class="tabsContainer">
        <van-tabs v-model="active">
          <van-tab title="直播间">
            <div class="liveCon">
              <live-img-con />
            </div>
          </van-tab>
          <van-tab title="助力产品">
            <div class="seckillContainer">
              <div class="seckillItem" v-for="(item,index) in seckillItem" :key="index">
                <div class="imgCon">
                  <img :src="item.img" @click="seckClick(index+1)" alt />
                </div>
                <div class="contentCon">
                  <div class="contentTitle">{{item.title}}</div>
                  <div class="priceCon">
                    助力价
                    <span class="seckillSym">￥</span>
                    <span class="seckillPrice">{{item.seckillPrice}}</span>
                    <span class="price">{{item.price}}</span>
                  </div>
                  <div class="btnCon">
                    <van-button size="mini" @click="seckClick(index+1)">立即助力</van-button>
                  </div>
                  <div class="numCon">
                    <div>
                      已抢
                      <span class="numColor">{{item.num}}</span>件，仅剩
                      <span class="numColor">{{item.remian}}</span>件
                    </div>
                    <div class="sliderCon">
                      <van-slider :value="item.rate" active-color="#051d2d" bar-height="1.38889vw">
                        <template #button>
                          <div style="display:none"></div>
                        </template>
                      </van-slider>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </van-tab>
          <van-tab title disabled></van-tab>
          <van-tab title disabled></van-tab>
          <van-tab title disabled></van-tab>
        </van-tabs>
      </div>

      <div class="goodsImgCon">
        <div class="goods1" @click="goodsClick(1)"></div>
        <div class="goods2" @click="goodsClick(2)"></div>
        <div class="goods3" @click="goodsClick(3)"></div>
        <div class="goods4" @click="goodsClick(4)"></div>
        <div class="goods5" @click="goodsClick(5)"></div>
        <div class="goods6" @click="goodsClick(6)"></div>
      </div>

      <div class="brandMsgCon"></div>
    </div>
  </div>
</template>

<script>
import {
  Swipe,
  SwipeItem,
  Tab,
  Tabs,
  Button,
  Slider,
  Toast,
  Dialog
} from "vant";
import seckillImg1 from "@/assets/切图/直播页面-正式稿_05.jpg";
import seckillImg2 from "@/assets/切图/直播页面-正式稿_08.jpg";
import seckillImg3 from "@/assets/切图/直播页面-正式稿_10.jpg";
import swipeImg1 from "@/assets/切图/直播页面-正式稿_01.jpg";
import swipeImg2 from "@/assets/切图/轮播图2.png";
import LiveImgCon from "@/components/LiveImgCon";
import { indexGoodsUrl } from "@/config/vantShops";
export default {
  components: {
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [Button.name]: Button,
    [Slider.name]: Slider,
    LiveImgCon
  },
  computed: {
    peopleCount() {
      return this.$store.state.activity.supCount;
    },
    isReady() {
      return this.$store.state.activity.isReady;
    },
    liveImg() {
      return this.$store.state.liveImg;
    }
  },
  data() {
    return {
      bgReady: false,
      active: 1,
      seckillItem: [
        {
          title: "成人乳胶枕防螨虫矫正脊椎",
          seckillPrice: "0.01",
          price: "￥399",
          img: seckillImg1,
          rate: 0,
          num: 0,
          remian: 0
        },
        {
          title: "儿童乳胶枕防螨虫矫正脊椎",
          seckillPrice: "0.01",
          price: "￥219",
          img: seckillImg2,
          rate: 0,
          num: 0,
          remian: 0
        },
        {
          title: "儿童万用棉毯",
          seckillPrice: "0.01",
          price: "￥159",
          img: seckillImg3,
          rate: 0,
          num: 0,
          remian: 0
        }
      ],
      swipeImg: [
        {
          img: swipeImg1
        },
        {
          img: swipeImg2
        }
      ]
    };
  },
  watch: {
    peopleCount: {
      deep: true,
      immediate: true,
      handler(val) {
        if (val && val.browseCount) {
          this.$nextTick(() => {
            this.$set(this.seckillItem, 0, {
              ...this.seckillItem[0],
              rate:
                (val.goods1Purchase / (val.goods1Purchase + val.goods1Remain)) *
                100,
              num: val.goods1Purchase,
              remian: val.goods1Remain
            });
            this.$set(this.seckillItem, 1, {
              ...this.seckillItem[1],
              rate:
                (val.goods2Purchase / (val.goods2Purchase + val.goods2Remain)) *
                100,
              num: val.goods2Purchase,
              remian: val.goods2Remain
            });
            this.$set(this.seckillItem, 2, {
              ...this.seckillItem[2],
              rate:
                (val.goods3Purchase / (val.goods3Purchase + val.goods3Remain)) *
                100,
              num: val.goods3Purchase,
              remian: val.goods3Remain
            });
          });
        }
      }
    }
  },
  created() {
    // Toast.loading({ forbidClick: true });
  },
  methods: {
    seckClick(item) {
      if (
        this.$store.state.activity.supInfoMy.asProductid &&
        this.$store.state.activity.supInfoMy.asProductid != item
      ) {
        //当前人有发起过助力，且点击的不是助力的商品
        // this.$router.push({
        //   name: "mySup",
        //   query: {
        //     ...this.$route.query,
        //     gid: this.$store.state.activity.supInfoMy.asProductid
        //   }
        // });
        Dialog({ message: "你已发起过助力，请点击已发起助力的商品进行查看" });
      } else {
        this.$router.push({
          name: "startSup",
          query: {
            ...this.$route.query,
            gid: item
          }
        });
      }
    },
    bgLoad(e) {
      console.log(e);
      this.bgReady = true;
      Toast.clear();
    },
    bgError(e) {
      Toast.clear();
      Dialog({ message: "活动图片加载失败" });
    },
    regClick() {
      if (
        this.$store.state.activity.enrollInfo &&
        this.$store.state.activity.enrollInfo.id
      ) {
        Dialog.alert({
          title: "温馨提示",
          message: "您已报名参加这场活动，请勿重复报名！"
        });
      } else {
        this.$router.push({
          name: "fillMsg",
          query: {
            type: "reg"
          }
        });
      }
    },
    goodsClick(e) {
      switch (e) {
        case 1: {
          location.href = indexGoodsUrl.E11;
          break;
        }
        case 2: {
          location.href = indexGoodsUrl.V9;
          break;
        }
        case 3: {
          location.href = indexGoodsUrl.E3C;
          break;
        }
        case 4: {
          location.href = indexGoodsUrl.A3;
          break;
        }
        case 5: {
          location.href = indexGoodsUrl.T109;
          break;
        }
        case 6: {
          location.href = indexGoodsUrl.T109;
          break;
        }
      }
    }
  }
};
</script>

<style lang="scss">
@mixin goods {
  position: absolute;
  width: 667px;
  height: 380px;
  left: 28px;
}
.activityIndex {
  .van-swipe__indicators {
    display: none;
  }
  .regCon {
    position: fixed;
    // display: none;
    right: 8px;
    top: 60px;
    width: 155px;
    height: 163px;
    background-image: url("../../../assets/我要报名.png");
    background-size: 100% 100%;
    animation: regScale 1s linear infinite alternate;
    z-index: 2;
  }
  @keyframes regScale {
    0% {
      transform: scale(1);
    }
    100% {
      transform: scale(0.8);
    }
  }
  .indexImgContainer {
    position: relative;
    // height: 4940px;
    .bgImg {
      width: 100vw;
      position: relative;
      z-index: -1;
      display: block;
    }
    .headCon {
      position: relative;
      .swipeImg {
        display: block;
        width: 100vw;
      }
    }
    .liveCon {
      background-color: white;
      text-align: center;
      padding: 12px;
    }

    .countCon {
      position: relative;
      background-image: url("../../../assets/切图/直播页面-正式稿_02.jpg");
      background-size: 100% auto;
      background-position: center;
      height: 80px;
      .countContainer {
        // position: absolute;
        // left: 0;
        // bottom: 10px;
        // height: 78px;
        // width: 100vw;
        display: flex;
        // align-items: center;
        justify-content: space-around;
        color: white;
        text-align: center;
        height: 100%;
        font-size: 20px;
        font-weight: 600;
        .count {
          flex: 1;
        }
        .countTop {
          margin-top: 17px;
        }
      }
    }

    .tabsContainer {
      .van-tabs--line .van-tabs__wrap {
        height: 86px;
      }
      .van-tabs__line {
        background-color: #101f60;
        height: 5px;
      }
      .van-tab__text {
        font-size: 28px;
      }
      .van-tab--active {
        font-weight: 600;
      }
      .seckillContainer {
        background-color: white;
        .seckillItem {
          padding: 44px 26px 56px 25px;
          border-top: 2px solid #d0d0d0;
          display: flex;
          .imgCon {
            padding-right: 32px;
            padding-top: 8px;
            img {
              width: 209px;
              height: 160px;
            }
          }
          .contentCon {
            flex: 1;
            .contentTitle {
              font-size: 28px;
              font-weight: 700;
              color: #030406;
            }
            .priceCon {
              font-size: 26px;
              color: #030406;
              padding-top: 10px;
              .seckillSym {
                font-size: 24px;
                color: #051c2a;
                font-weight: 600;
              }
              .seckillPrice {
                font-size: 40px;
                color: #051c2a;
                font-weight: 600;
              }
              .price {
                font-size: 22px;
                text-decoration: line-through;
                color: #d7d7d7;
              }
            }
            .btnCon {
              display: flex;
              justify-content: flex-end;
              .van-button--mini {
                font-size: 25px;
                padding: 16px 34px;
                background-color: #0b2639;
                border-color: #0b2639;
                color: white;
                border-radius: 10px;
                height: 45px;
              }
            }
            .numCon {
              color: #828282;
              font-size: 0.1rem;
              display: flex;
              justify-content: space-between;
              margin-top: 12px;
              .numColor {
                color: $font-color-primary;
              }
              .sliderCon {
                display: flex;
                align-items: flex-end;
                padding-bottom: 5px;
                width: 170px;
              }
            }
          }
        }
      }
    }

    .liveTab {
      position: absolute;
      left: 0;
      top: 798px;
      height: 88px;
      width: 140px;
    }

    .goodsImgCon {
      position: relative;
      width: 100vw;
      height: 2825px;
      background-image: url("../../../assets/切图/直播页面-正式稿_12.jpg");
      background-size: 100% auto;
      background-position: center;
      .goods1 {
        @include goods;
        top: 178px;
      }
      .goods2 {
        @include goods;
        top: 618px;
      }
      .goods3 {
        @include goods;
        top: 1060px;
      }
      .goods4 {
        @include goods;
        top: 1494px;
      }
      .goods5 {
        @include goods;
        top: 1928px;
      }
      .goods6 {
        @include goods;
        top: 2374px;
      }
    }

    .brandMsgCon {
      width: 100vw;
      height: 756px;
      background-image: url("../../../assets/切图/直播页面-正式稿_13.jpg");
      background-size: 100% auto;
      background-position: center;
    }
  }
}
</style>